<?php
class entity_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function checkLoginLB($username, $password)
    {            
            $query = "SELECT * FROM logbook_account WHERE ACC_NAME = '$username' and ACC_PASSWORD = md5('$password') ";
            return $this->db->query($query);
    }
    
    public function checkLoginEV($username, $password)
    {            
            $query = "SELECT * FROM ev_account WHERE USERNAME = '$username' and PASSWORD = md5('$password') ";
            return $this->db->query($query);
    }
    
    public function daftarLB($username,$password)
    {
            $q = $this->db->query("SELECT * FROM logbook_account WHERE ACC_Name = '$username'");
            if($q->num_rows() == 0)
            {
                $hasil = md5($password);
                $data = array(
                           'ACC_NAME' => $username,
                           'ACC_PASSWORD' => $hasil
                        );
                $this->db->insert('logbook_account', $data);
                return "oke";
            }
            else
            {
                return "Nama sudah terdaftar";
            }
    }
    
    public function daftarEV($username,$password,$depart)
    {
            $q = $this->db->query("SELECT * FROM ev_account WHERE USERNAME = '$username'");
            if($q->num_rows() == 0)
            {
                $hasil = md5($password);
                $data = array(
                           'USERNAME' => $username,
                           'PASSWORD' => $hasil,
                           'DEPARTEMENT' => $depart
                        );
                $this->db->insert('ev_account', $data);
                return "oke";
            }
            else
            {
                return "Nama sudah terdaftar";
            }
    }
    public function getMemberLBInfo($username)
    {
            return $this->db->get_where('logbook_account', array('ACC_NAME' => $username));
    }
    
    public function getMemberEVInfo($username)
    {
            return $this->db->get_where('ev_account', array('USERNAME' => $username));
    }
    
    public function submitActivity($time, $nama, 
                    $guest, $aff, $purpose, $counter)
    {
        $data = array
        (
            'ACC_NAME' => $nama,
            'START_TIME' => $time,
            'END_TIME' => $time,
            'GUEST_NAME' => $guest,
            'AFFILIATION' => $aff,
            'PURPOSE' => $purpose,
            'MEASURE' => $counter
        );
        $this->db->insert('logbook_activity',$data);
        return "oke";
    }
    
    public function getAllActivity()
    {
        $query = "SELECT * FROM `logbook_activity`";
        return $this->db->query($query);
    }
    
    
    
//    EVENT MANAGER
    public function getDepartment($name)
    {
        return $this->db->get_where('ev_account', array('USERNAME' => $name));
    }
    public function getNameDepartment($id)
    {
        return $this->db->get_where('ev_departement', array('DEPART_ID' => $id));
    }
    public function setLecture($username,$timeSubmit,$tipe,$lecName,$aff,$place,$subject,$date )
    {
        $data = array
        (
            'USERNAME' => $username,
            'LECTURE_SUBMIT' => $timeSubmit,
            'LECTURE_TYPE' => $tipe,
            'LECTURE_USERNAME' => $lecName,
            'LECTURE_AFFILATION' => $aff,
            'LECTURE_PLACE' => $place,
            'LECTURE_SUBJECT' => $subject,
            'LECTURE_DATE' => $date
        );
        $this->db->insert('ev_lecture',$data);
        return "oke";
    }
    
    public function setExchange($username,$timeSubmit,$tipe,$student,$univ,$country,
            $starty,$starts,$endy,$ends,$tstudy)
    {
        $data = array (
            'USERNAME' => $username,
            'EX_SUBMIT'=> $timeSubmit,
            'EX_TYPE' => $tipe,
            'EX_USERNAME' => $student,
            'EX_UNIVERSITY' => $univ,
            'EX_COUNTRY' => $country,
            'EX_STARTYEAR' => $starty,
            'EX_STARTSEMESTER' => $starts,
            'EX_ENDYEAR' => $endy,
            'EX_ENDSEMESTER' => $ends,
            'EX_TYPESTUDY' => $tstudy
        );
        $this->db->insert('ev_exchange',$data);
        return "oke";
    }
    public function setAgree($username,$tglSubmit,$tipe,$aname, $adate,$partner,$participant,$country)
    {
        $data = array
        (
            'USERNAME' => $username,
            'AGREE_SUBMIT' => $tglSubmit,
            'AGREE_TYPE' => $tipe,
            'AGREE_EVENTNAME' =>$aname,
            'AGREE_DATE' => $adate,
            'AGREE_PARTNER' => $partner,
            'AGREE_PARTICIPANT' => $participant,
            'AGREE_COUNTRY' => $country
        );
        $this->db->insert('ev_agreement',$data);
        return "oke";
    }
    
    
    
    
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
